package cn.iocoder.yudao.module.yyzx.service.nurse_records;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_records.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_records.Nurse_recordsDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.yyzx.dal.mysql.nurse_records.Nurse_recordsMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.yyzx.enums.ErrorCodeConstants.*;

/**
 * 护理记录 Service 实现类
 *
 * @author lovedream
 */
@Service
@Validated
public class Nurse_recordsServiceImpl implements Nurse_recordsService {

    @Resource
    private Nurse_recordsMapper nurse_recordsMapper;

    @Override
    public Integer createNurse_records(Nurse_recordsSaveReqVO createReqVO) {
        // 插入
        Nurse_recordsDO nurse_records = BeanUtils.toBean(createReqVO, Nurse_recordsDO.class);
        nurse_recordsMapper.insert(nurse_records);
        // 返回
        return nurse_records.getId();
    }

    @Override
    public void updateNurse_records(Nurse_recordsSaveReqVO updateReqVO) {
        // 校验存在
        validateNurse_recordsExists(updateReqVO.getId());
        // 更新
        Nurse_recordsDO updateObj = BeanUtils.toBean(updateReqVO, Nurse_recordsDO.class);
        nurse_recordsMapper.updateById(updateObj);
    }

    @Override
    public void deleteNurse_records(Integer id) {
        // 校验存在
        validateNurse_recordsExists(id);
        // 删除
        nurse_recordsMapper.deleteById(id);
    }

    private void validateNurse_recordsExists(Integer id) {
        if (nurse_recordsMapper.selectById(id) == null) {
            throw exception(NURSE_RECORDS_NOT_EXISTS);
        }
    }

    @Override
    public Nurse_recordsDO getNurse_records(Integer id) {
        return nurse_recordsMapper.selectById(id);
    }

    @Override
    public PageResult<Nurse_recordsDO> getNurse_recordsPage(Nurse_recordsPageReqVO pageReqVO) {
        return nurse_recordsMapper.selectPage(pageReqVO);
    }

}